package com.accp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.accp.entity.DataResult;
import com.accp.entity.Hotevents;
import com.accp.service.HotevensService;
import com.baomidou.mybatisplus.core.metadata.IPage;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/hot")
@Slf4j
public class HotevensController {
		@Autowired
		private HotevensService hotservice;
		
		
		@GetMapping("/findAll")
		public DataResult findAll(
				@RequestParam(value="PageNum",required=false,defaultValue="1")int PageNum,
				@RequestParam(value="PageSize",required=false,defaultValue="3")int PageSize,
				String keyWord){
				IPage<Hotevents> ipage =  hotservice.findAll(PageNum, PageSize, keyWord);
				return DataResult.getSuccessResult(ipage);
		}
		
		@GetMapping("fetch")
		public DataResult fetchEvent(int id){
			try {
				Hotevents event = hotservice.fetchEvent(id);
				return DataResult.getSuccessResult(event);
			} catch (Exception e) {
				// TODO: handle exception
				return DataResult.getErrorResult(505, null, "热点信息不存在");
			}
		}
}
